#include "Core/Profile/CodeProfile.h"
#include "Core/Plugin/PluginManager.h"
#include "Core/GUI/IGUIPlugin.h"
#include "Core/GUI/IGUIContext.h"
#include "Core/GUI/Application/IApplication.h"
#include "Core/GUI/Application/IWindow.h"
#include "Core/GUI/Button/IButton.h"
#include "Core/GUI/Slider/ISlider.h"
#include "Core/GUI/Tab/ITab.h"
#include "Core/GUI/Layout/IVerticalLayout.h"
#include "Core/GUI/Layout/IHorizontalLayout.h"
#include "GUITest.h"

void OnClick()
{
	std::cout << "Button Click"<< std::endl;
}

void OnValueChanged(int _value)
{
	std::cout << "Slider value changed : " << _value << std::endl;
}

GUITest::GUITest(int argc, char *argv[])
{
	m_argc = argc;
	m_argv = argv;
}

const char * GUITest::GetName() const
{
	return "[GUI] GUI Test";
}

Core::error GUITest::Create()
{
	if(Failed(UnitTest::Create()))
		return Core::errFailed;

	return Core::errOK;
}

Core::error GUITest::Destroy()
{
	if(Failed(UnitTest::Destroy()))
		return Core::errFailed;

	return Core::errOK;
}

Core::error GUITest::Execute()
{
	PROFILE(GetName());

	Core::GUI::IGUIPlugin * pPlugin = Core::Plugin::PluginManager::GetInstance().RegisterPlugin<Core::GUI::IGUIPlugin>(Core::Plugin::GUI, "GUI");
	if (pPlugin == NULL)
	{
		return Core::errFailed;
	}
	
	Core::GUI::IGUIContext * pContext = pPlugin->CreateContext();
	
	Core::GUI::IApplication * pApplication = pContext->CreateApplication(m_argc, m_argv);
	
	// Creation Window & widgets
	Core::GUI::IWindow * pWindow = pApplication->CreateWindowApp("Window test", 800, 600);
	//pWindow->SetBackgroundColor(0,0,128);
	pWindow->Loop();
	
	pApplication->DestroyWindowApp(pWindow);

	pPlugin->DestroyContext(pContext);

	Core::error e = Core::Plugin::PluginManager::GetInstance().UnregisterPlugin(Core::Plugin::GUI);
	if (e != Core::errOK)
	{
		return Core::errFailed;
	}

	return Core::errOK;
}
